home *** CD-ROM | disk | FTP | other *** search
- /* insert.c - insertion sort function */
- /* uses pointers to actual data elements and a compare function */
- #include "stdio.h"
-
- int insert(pa,na,pcomp)
- char *pa[] ; /* number of pointers to elements to be sorted */
- int na ; /* number of elements to be sorted */
- int (*pcomp) () ; /* pointer to compare function */
- {
- int i ; /* indeces for loops */
- int j ; /* for inner loop - optomize */
- char *ptemp ; /* temporary storage for one pointer */
-
- for( i=1 ; i < na ; i = i + 1 )
- { /* insert the i-th element into the storage array */
- ptemp = pa[i] ;
- j = j - 1 ;
- while( (j >= 0 ) && ( (*pcomp) (ptemp,pa[j]) <= 0 ) )
- { pa[j+1] = pa[j] ;
- j = j - 1 ;
- }
- pa[j+1] = ptemp ;
- }
- }
-
-
-